package edu.ynu.se.xiecheng.achitectureclass.service.Impl;

import edu.ynu.se.xiecheng.achitectureclass.entity.UserEntity;
import edu.ynu.se.xiecheng.achitectureclass.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import edu.ynu.se.xiecheng.achitectureclass.dao.UserDao;

import java.util.Optional;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public boolean login(String username, String password) {
        // 根据用户名查询用户
        Optional<UserEntity> userOptional = userDao.findByUserName(username);
        // 如果用户不存在，返回false
        if (!userOptional.isPresent()) {
            return false;
        }
        UserEntity user = userOptional.get();
        return password.equals(user.getPassword());
    }
}
